/**
 * 画面初期化处理
 */
$(function() {	
	setListTableCss("dataInfo");
});

/**
 * 新增工作人员初始化
 * @return
 */
function add()
{
	doAction(document.forms["workerForm"], "system/worker-add.action");
}

/**
 * 更新工作人员初始化
 * @return
 */
function modify(workerCode)
{
	$('#workerCode').val(workerCode);
	doAction(document.forms["workerForm"], "system/worker-modify.action");
}

/**
 * 查看工作人员详细信息.
 * @return
 */
function detail(workerCode)
{
	$('#workerCode').val(workerCode);
	doAction(document.forms["workerForm"], "system/worker-detail.action");
}

/**
 * 画面输入检查
 * @return
 */
function doCheck()
{
	if (isEmptyStr($('#workerCode').val()))
	{
		alert(getMessage(MESSAGE_001, '编号'));
		return false;
	}
	else if ($('#workerCode').val().Trim().length > 100)
	{
		alert(getMessage(MESSAGE_003, '编号', '100'));
		return false;
	}

	if (isEmptyStr($('#workerName').val()))
	{
		alert(getMessage(MESSAGE_001, '姓名'));
		return false;
	}
	else if ($('#workerName').val().Trim().length > 100)
	{
		alert(getMessage(MESSAGE_003, '姓名', '100'));
		return false;
	}

	if (isEmptyStr($('#birthday').val()))
	{
		alert(getMessage(MESSAGE_001, '出生日期'));
		return false;
	}

	if (isEmptyStr($('#idCardNo').val()))
	{
		alert(getMessage(MESSAGE_001, '身份证号'));
		return false;
	}
	else if (!$('#idCardNo').val().isIDCard())
	{
		alert(getMessage(MESSAGE_004));
		return false;
	}

	if (isEmptyStr($('#nation').val()))
	{
		alert(getMessage(MESSAGE_001, '民族'));
		return false;
	}
	else if ($('#nation').val().Trim().length > 10)
	{
		alert(getMessage(MESSAGE_003, '民族', '10'));
		return false;
	}

	if (isEmptyStr($('#education').val()))
	{
		alert(getMessage(MESSAGE_002, '学历'));
		return false;
	}

	if (isEmptyStr($('#jobId').val()))
	{
		alert(getMessage(MESSAGE_002, '岗位'));
		return false;
	}

	if (isEmptyStr($('#employedDate').val()))
	{
		alert(getMessage(MESSAGE_001, '入职时间'));
		return false;
	}

	return true;
}

/**
 * 新增岗位
 * @return
 */
function insert()
{
	if (doCheck())
	{
		var temp;
		// 校验工作人员编号存在性
		$.ajax({
		  type: "POST",
		  async: false, // 使用同步方式执行AJAX
		  url: "system/worker-checkWorkerCodeExist.action",
		  data:	"worker.workerCode="+$("#workerCode").val()+"&random="+Math.random(),
	 	  success:function(data){
			  	if(data > 0)
			  	{
			  		alert("(工作人员编号："+$("#workerCode").val()+")已经存在！");
			  		$("#workerCode").focus();
			  		temp = "false";
			  	}
		 	}
		});
		if(temp=="false")
		{
			return false;
		}
		doAction(document.forms["workerForm"], "system/worker-insert.action");
	}
}

/**
 * 更新岗位
 * @return
 */
function update()
{
	if (doCheck())
	{
		doAction(document.forms["workerForm"], "system/worker-update.action");
	}
}

function deleteWorker(workerCode)
{
	if(confirm("确定要删除此条记录吗？"))
	{
		$('#workerCode').val(workerCode);
		doAction(document.forms["workerForm"], "system/worker-delete.action");
	}
}
/**
 * 返回列表页面
 * @return
 */
function back(flag)
{
	if(flag)
	{
	
		if(flag && confirm("确定要返回工作人员列表吗？"))
		{
			commonSearch();
		}
	}
	else
	{
		commonSearch();
	}
}

/**
 * 查询角色权限
 * @return
 */
function search()
{
	$("#pageNow").val("0");
	commonSearch();
}

function commonSearch()
{
	doAction(document.forms["workerForm"],"system/worker-list.action");
}

/**
 * 分页
 * @return
 */
function page(pageNow)
{
	$("#pageNow").val(pageNow);
	commonSearch();
}
